#include "server.h"

int main() {
    int server_fd = init_server();
    printf("Server started on %s:%d\n", SERVER_IP, SERVER_PORT);

    client_mag clients[MAX_CLIENTS];
    for (int i = 0; i < MAX_CLIENTS; i++) {
        clients[i].socket_fd = -1;
        clients[i].state = CLIENT_UNREGISTERED;
    }

    fd_set read_fds;
    int max_fd = server_fd;

    while (1) {
        FD_ZERO(&read_fds);
        FD_SET(server_fd, &read_fds);

        for (int i = 0; i < MAX_CLIENTS; i++) {
            if (clients[i].socket_fd != -1) {
                FD_SET(clients[i].socket_fd, &read_fds);
                if (clients[i].socket_fd > max_fd) {
                    max_fd = clients[i].socket_fd;
                }
            }
        }

        int activity = select(max_fd + 1, &read_fds, NULL, NULL, NULL);
        if (activity < 0 && errno != EINTR) {
            handle_error("select error");
        }

        // 处理新连接和客户端数据...
    }

    close(server_fd);
    return 0;
}